package com.sky.controller.admin;

import com.sky.dto.CategoryDTO;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**分类管理
 *
 */
@RestController
@Slf4j
@RequestMapping("/admin/category")
@Api(tags = "分类相关")
public class CategoryController {

    @Autowired
    private CategoryService categoryService;
    /**新增菜品分类
     *
     */
    @ApiOperation("新增菜品分类")
    @PostMapping
    public Result addCategory(@RequestBody CategoryDTO categoryDTO){
        log.info("新增菜品分类，参数{}",categoryDTO);
        categoryService.addCategory(categoryDTO);
        return Result.success();
    }


    @ApiOperation("分类分页查询")
    @GetMapping("/page")
    public Result<PageResult> page(CategoryPageQueryDTO categoryPageQueryDTO){
        log.info("分类信息分页查询参数，{}",categoryPageQueryDTO);
        PageResult pageResult = categoryService.page(categoryPageQueryDTO);
        return Result.success(pageResult);
    }

    @ApiOperation("类别启用禁用")
    @PostMapping("status/{status}")
    public Result startOrstop(@PathVariable Integer status,Long id){
        log.info("类别禁用启用参数{}，{}",status,id);
        categoryService.startOrstop(status,id);
        return Result.success();

    }

    @ApiOperation("根据id删除分类")
    @DeleteMapping
    public Result delete(Long id){

        categoryService.delete(id);
        return Result.success();

    }

    @ApiOperation("修改分类")
    @PutMapping
    public Result alterCategory(@RequestBody CategoryDTO categoryDTO){

        categoryService.alterCategory(categoryDTO);
        return  Result.success();
    }



    @ApiOperation("根据类型查询分类")
    @GetMapping("/list")
    public Result<List<Category>> findByType(Integer type){
        log.info("根据类型查询分类{}",type);
        List<Category> list  = categoryService.findByType(type);
        return Result.success(list);

    }
}
